<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>


<html>
<head>
    <title>修改汽车产品信息</title>
    <%@ include file="../../common/base.jsp" %>

    <script type="text/javascript">

        function addSubmit() {
            if (!validateContentNotNull('productsName', 1, 30, '产品名称', true)) {
                return false;
            }

            $.ajax({
                type: "POST",
                url: "${pageContext.request.contextPath}/carProducts/updateCarproducts",
                dataType: "json",
                data: getParams(),
                success: function (data) {
                    if (data.errorCode == 0) {
                        prompt.alert("修改汽车产品信息成功！");

                        setTimeout(function () {
                            window.location.href = "${pageContext.request.contextPath}/carProducts/showCarproducts";
                        }, 2000);
                    } else {
                        prompt.alert(data.msg);
                    }
                }
            });
        }

        //获取form表单所有参数
        function getParams() {
            var json = {};
            $(".content input,.content select").each(function (i, e) {
                json[$(e).attr("id")] = $(e).attr("value");
            });
            return json;
        }

        // 数字必填验证
        function verify_Number(id,thisName) {
            var val = $("#"+id).val();
            $("#"+id+"Zhu").html("");
            $("#"+id+"s").hide();
            $("#"+id+"Zhu").hide();
            //开始验证
            if (verifyEmpty(val)) {
                if (thisName != '' && thisName != null) {
                    $("#"+id+"Zhu").html(thisName+"值不能为空！");
                } else {
                    $("#"+id+"Zhu").html("该值不能为空！");
                }
                $("#"+id+"Zhu").show();
                return false;
            }else{
                //纯数字正则
                var numReg = new RegExp("^(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*))$");

                if(!numReg.test(val)){
                    if (thisName != '' && thisName != null) {
                        $("#"+id+"Zhu").html(thisName+"由数字组成！");
                    } else {
                        $("#"+id+"Zhu").html("该值由数字组成！");
                    }
                    $("#"+id+"Zhu").show();
                    return false;
                }
                $("#"+id+"s").show();
                return true;
            }
        }

    </script>

</head>

<body id="body">
<!--head-->
<div id="head">
    <jsp:include page="../../common/head.jsp"></jsp:include>
</div>
<!--head end-->
<!--container-->
<div id="container">
    <div id="pageId" style="display: none;">05-04</div>
    <!--sidebar-->
    <%@ include file="../../common/menu.jsp" %>
    <!--sidebar-->
    <!--main-->
    <div class="main" id="mainDiv">
        <div class="channel_manage">
            <div class="location" style="background-position:22px -29px;">
                系统配置<span>&gt;</span>产品管理<span>&gt;</span>添加产品
            </div>
            <form method="post" enctype="multipart/form-data">
                <!--content-->
                <div class="content">
                    <div class="inputInfoList3">
                        <ul class="recharge_list" style="width:600;">
                            <li>
                                <label>上级产品编码</label>${parentId}${parentCarproductsName}
                            </li>

                            <li>
                                <label>产品编码</label>
                                <input type="text" id="id" name="id" value="${carproducts.id}" readonly
                                       onFocus="this.style.border = '1px solid #2A7CCF'"
                                       onblur="carProductsIdBlur();this.style.border = '1px solid #D5D5D5'" maxlength="10"/>
                                <span style="position:absolute;left:76%;top:9px;color:red;" class="red">*</span>
                                <i style="display: none;background-position: left center;" id="ids" class="s_tips"></i>
                                <i style="display: none;background-position: left center;padding-left:28%;" id="idZhu" class="zhu_shi_2"></i>
                            </li>
                            <li>
                                <label>产品名称</label>
                                <input type="text" id="productsName" name="productsName" value="${carproducts.productsName}"
                                       onFocus="this.style.border = '1px solid #2A7CCF'"
                                       onblur="validateContentNotNull('productsName',1,30,'产品名称');this.style.border = '1px solid #D5D5D5'"
                                       maxlength="10"/>
                                <span style="position:absolute;left:76%;top:9px;color:red;" class="red">*</span>
                                <i style="display: none;background-position: left center;" id="productsNames" class="s_tips"></i>
                                <i style="display: none;background-position: left center;padding-left:28%;" id="productsNameZhu" class="zhu_shi_2"></i>
                            </li>

                            <li style="position:relative;">
                                <input type="hidden" id="parentId" name="parentId" value="${carproducts.parentId}"/>
                                <label>所属父产品</label><input type="text" value="${parentCarproductsName}" readonly
                                                           onFocus="this.style.border = '1px solid #2A7CCF'"
                                                           onBlur="this.style.border = '1px solid #D5D5D5'">
                            </li>
                            <li>
                                <label>产品类型</label>
                                <select id="type" name="type" style="width: 280px;">
                                    <option value="">选择产品类型</option>
                                    <option value="1" <c:if test="${carproducts.type == 1}"> selected</c:if>>公司</option>
                                    <option value="2" <c:if test="${carproducts.type == 2}"> selected</c:if>>汽车产品</option>
                                    <option value="3" <c:if test="${carproducts.type == 3}"> selected</c:if>>子产品类型</option>
                                </select>
                            </li>
                            <li>
                                <label>产品所属保养类型</label>
                                <select id="maintenanceId" name="maintenanceId" style="width: 280px;">
                                    <option value="">选择保养类型</option>
                                    <c:forEach var="item" items="${maintenanceList}" varStatus="vatS">
                                        <option value="${item.id}" <c:if test="${carproducts.maintenanceId == item.id}"> selected</c:if>>${item.maintenanceName}</option>
                                    </c:forEach>
                                </select>
                            </li>
                            <li>
                                <label>汽车产品最低价</label>
                                <input type="text" id="minPrice" name="minPrice" value="${carproducts.minPrice}"
                                       onFocus="this.style.border = '1px solid #2A7CCF'"
                                       onblur="verify_Number('minPrice','汽车产品最低价');this.style.border = '1px solid #D5D5D5'"
                                       maxlength="10"/>
                                <span style="position:absolute;left:76%;top:9px;color:red;" class="red">*</span>
                                <i style="display: none;background-position: left center;" id="minPrices" class="s_tips"></i>
                                <i style="display: none;background-position: left center;padding-left:28%;" id="minPriceZhu" class="zhu_shi_2"></i>
                            </li>
                            <li>
                                <label>汽车产品最高价</label>
                                <input type="text" id="maxPrice" name="maxPrice" value="${carproducts.maxPrice}"
                                       onFocus="this.style.border = '1px solid #2A7CCF'"
                                       onblur="verify_Number('maxPrice','汽车产品最高价');this.style.border = '1px solid #D5D5D5'"
                                       maxlength="10"/>
                                <span style="position:absolute;left:76%;top:9px;color:red;" class="red">*</span>
                                <i style="display: none;background-position: left center;" id="maxPrices" class="s_tips"></i>
                                <i style="display: none;background-position: left center;padding-left:28%;" id="maxPriceZhu" class="zhu_shi_2"></i>
                            </li>
                        </ul>
                        <div class="button_wrap">
                            <a href="javascript:void(0);" onClick="addSubmit();" class="bg_green">完成</a>
                            <input type="reset" value="重置">
                        </div>
                    </div>
                </div>
                <!--content-->
            </form>
            <!--foot-->
            <%@ include file="../../common/foot.jsp" %>
            <!--foot-->
        </div>
    </div>
    <!--main-->
</div>
<script src="${pageContext.request.contextPath}/static/js/basic.js"></script>

</body>
</html>
